<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title></title>
<link rel="stylesheet" type="text/css" href="css/hui.css" />
<style>
	
	body {margin-left: 0px;margin-top: 0px;margin-right: 0px;margin-bottom: 0px;overflow: hidden;}
</style>
</head>
<body>
<header class="hui-header">
    <div id="hui-back"></div>
    <h1 id="ttt"></h1>
</header>
<div id="duzi" class="hui-wrap">
    <iframe id="dtl" width='100%' height='90%' frameborder='0' name="_blank" id="_blank" src="">
    	
    	
    </iframe>
</div>
<div id="hui-footer" style="padding: 0px;box-shadow: none;">
	<div id="addZX" onclick="addZX()" style="width: 50%;background-color:#CCCCCC;height: 100%;color: red;text-align: center;float: left;padding-top: 13px;">添加自选</div>
	<div style="width: 50%;background-color:#EF4F4F;height: 100%;color: white;text-align: center;padding-top: 13px;">创建策略</div>
</div>
<script src="js/hui.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script>
	var user = localStorage.getItem("nowUser");//取回students变量  
		user = JSON.parse(user);//把字符串转换成JSON对象 
	var code ="";
	var name = "";
	function GetQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}
hui.ready(function(){
		
		if(user==null||user==""){
			hui.open("login.html");
		}
		
    	code = GetQueryString("code");
    	name = localStorage.getItem("name");
    	if(code==null||code==""){
    		hui.open("zixuan.html");
    	}
    	$("#ttt").html(localStorage.getItem("name"));
    	$("#dtl").attr("src","http://47.104.150.165:8088/#quote?code="+code);
    			hui.post(
		    url_root+':8080/st/servlet/OptionalServlet',
		    {method:'haveOptional', userId:user.id,sCode:code},
		    function(msg){
		    	if(msg=="exist"){
		    		$("#addZX").html("删除自选");
		    	}
		    },
		    function(e){
		        hui.iconToast('网络故障', 'warn');
		    }
		);
	});
function addZX(){
		if($("#addZX").html()=="删除自选"){
			
			hui.post(
			   url_root+':8080/st/servlet/OptionalServlet',
			    {method:'delOptional', userId:user.id,sCode:code},
			    function(msg){
			    	if(msg=="success"){
			        hui.toast("删除成功");
			        $("#addZX").html("添加自选");
			       }
			    
			    },
			    function(e){
			        hui.iconToast('网络故障', 'warn');
			    }
			);
			
			return;
		}
		
		
		hui.post(
		    url_root+':8080/st/servlet/OptionalServlet',
		    {method:'addOptional', userId:user.id,sCode:code,sName:name},
		    function(msg){
		    	if(msg=="success"){
		        hui.toast("添加成功");
		        $("#addZX").html("删除自选");
		       }
		    	if(msg=="exist"){
		    		return;
		    	}
		    },
		    function(e){
		        hui.iconToast('网络故障', 'warn');
		    }
		);
	
}
</script>

</body>
</html>